use strict;
use warnings;
use apikey;;
use Lingua::Translate;
use URI::Escape;

#$safe = uri_escape("10% is enough\n");
# $verysafe = uri_escape("foo", "\0-\377");
# $str  = uri_unescape($safe);

 Lingua::Translate::config
     (
         back_end => 'Google',
      api_key => $apikey::api_key,
         referer  => $apikey::referer ,
     );

 my $xl8r = Lingua::Translate->new(src => 'en', dest => 'sq');

# # prints 'My hovercraft is full of eels'


my $lastmsg="TODO";
while (<>)
{
    if (/msgid \"(.+)\"/ )
    {
	print $_;
	$lastmsg=$1;
    }
    elsif (/\s*\"(.+)\"/ )
    {
	print $_;
	$lastmsg.=$1;
    }
    elsif (/msgstr \"\"/)
    {
	my $newmsg = uri_escape("$lastmsg");
	my $news= $xl8r->translate($newmsg);

#	$news =~ s/MYPROCENTSPECIAL/%/g;


	print "msgstr \"$news\"\n";
	$lastmsg="";
    }
    else
    {
	print $_;
    }
}
